package com.mauth.common.entity.auth;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.mauth.common.entity.base.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import java.util.Set;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class UserAuthority extends BaseEntity {

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "authority_id", referencedColumnName = "id", nullable = false)
    private Authority authority;

    @OneToMany(mappedBy = "userAuthority", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @OrderBy("id ASC")
    @BatchSize(size = 20)
    private Set<Qualifier> qualifiers;

    @ManyToOne(fetch = FetchType.EAGER)
    @JsonBackReference
    @JoinColumn(
            name = "role_id",
            referencedColumnName = "id",
            nullable = false,
            columnDefinition = "integer")
    private Role role;
}
